import 'package:flutter/material.dart';

import './page/home.dart';

import './page/not_found_page.dart';

import './page/baidu.dart';


class MyRoute {
  // 路由表
  static final Map<String, WidgetBuilder> routeTable = {
    '/' : (content) => Home(),
    '/page/baidu' : (content) => BaiDu(),

  };

  // 动态生成路由
  static final onGenerateRoute = (RouteSettings settings) {
    // 从路由表得到builder
    final name = settings.name;
    var builder = routeTable[name];

    // 如果路由表中未定义，跳转到未定义路由页面
    if (builder == null) {
      builder = (content) => NotFoundPage();
    }

    // 构建动态的route
    final route = MaterialPageRoute(
      builder: builder,
      settings: settings,
    );

    return route;
  };
}